package com.moss.cloud.remote.biz.utils;

import com.alibaba.fastjson2.JSONObject;
import com.moss.cloud.common.core.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;

import java.util.function.Consumer;

@Slf4j
public class BaiDuIpUtil {
    private static final String IP_API = "https://api.map.baidu.com/location/ip?ak=6CQhgGjFgptClQZjrG3OmcRAxBkd2a8O&coor=bd09ll&ip=";

    public static final Integer STATUS = 0;

    /**
     * 构建WebClient请求
     *
     * @param url
     * @return
     */
    public static String buildWebClient(String url) {
        Consumer<HttpHeaders> consumer = httpHeaders -> {
        };
        return HttpUtil.doGet(url, consumer);
    }

    /**
     * 获取IP地址
     *
     * @param ip
     * @return
     */
    public static JSONObject getIpAddr(String ip) {
        String url = IP_API + ip;
        JSONObject json = JSONObject.parseObject(buildWebClient(url));
        log.info("请求百度IP地制定为接口返回:{}",json);
        return json;
    }

    public static void main(String[] args){
        System.out.println(getIpAddr("113.201.248.151"));
    }
}

